using UnityEngine;
using QFramework;
using System.Linq;

namespace ProjectSurvivor
{
	public partial class TreasureChesPanel : ViewController,IController
	{
		void Awake()
		{
			BtnSure.onClick.AddListener(() =>
			{
				Time.timeScale = 1.0f;
				this.Hide();
			});
		}
		public void OnEnable()
		{
			var expUpgradeSystem = this.GetSystem<ExpUpgrdeSystem>();
			var upgradeItems = expUpgradeSystem.Items.Where(item => !item.UpgradeFinish).ToList();
			if (upgradeItems.Any())
			{
				var item = upgradeItems.GetRandomItem();
				ConTent.text = item.Description;
				item.Upgrade();
			}
			else
			{
				if (Global.HP.Value <= Global.MaxHP.Value)
				{
					if (Random.Range(0, 0.1f) < 0.2f)
					{
						ConTent.text = "恢复血量";
						AudioKit.PlaySound("hp");
						Global.HP.Value++;
						return;
					}
				}
			}
			ConTent.text = "增加50金币";
			Global.Coin.Value += 50;
			
		}
		
		public void OnBeforeDestroy()
		{

		}

        public IArchitecture GetArchitecture()
        {
            return Global.Interface ;
        }
    }
}
